// packageA/components/service-order-list/index.js
const baseUrl = require("../../../api/config").dev; //这里用的是ES6的写法
const WXAPI = require("../../../api/api");
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    list: {
      type: Array,
      value: [],
    },
    isLoading: {
      type: Boolean,
      value: false,
    },
  },
  // 监听传入的变量,当传入的值发生变化时,触发方法
  observers: {
    list: function (val) {
      // val=》就是父组件传入组件中的tabsList数据
      let obj = {
        1: 3,
        2: 3,
        3: 3,
        4: 2,
        9: 1,
      };
      if (val && val.length > 0) {
        for (let i = 0; i < val.length; i++) {
          val[i].iStatus2 = obj[val[i].iStatus];
        }
      }

      this.setData({
        listData: val,
      });
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    listData: [],
    imgBaseUrl: `${baseUrl["imgBaseUrl"]}`,
  },

  /**
   * 组件的方法列表
   */
  methods: {
    toPay(e) {
      const { item } = e.currentTarget.dataset;
      wx.navigateTo({
        url: `/packageA/pages/order-pay-type/index?totalPrice=${item.dOrderAmount}&type=2&id=${item.sId}`,
      })
      // wx.navigateTo({
      //   url: `/packageA/pages/order-pay/index?id=${item.ProductOrderGoods[0].sGoodsId}`,
      // });
    },
    toEvaluate(e) {
      const { item } = e.currentTarget.dataset
      let objStr = JSON.stringify({
        id: item.sId,
        sOrgId: item.sOrgId,
        goodsList: item.ProductOrderGoods
      })
      wx.navigateTo({
        url: `/packageA/pages/evaluate-goods/index?type=1&objStr=${objStr}`,
      });
    },
    sureReceiveGoods(e){
      const {id,} = e.currentTarget.dataset
      let _this = this
      wx.showModal({
        title: '警告',
        content: '是否确认收货？',
        complete: async (res) => {
          if (res.confirm) {
             let res = await WXAPI.sureReceive(id)
             if(res.data.code == 0) {
               wx.showToast({
                 title: res.data.message,
               })
               _this.triggerEvent('updateList')
             }
          }
        }
      })
    },
    viewOrder(event) {
      wx.navigateTo({
        url: `/packageA/pages/goods-order-detail/index?id=${event.currentTarget.dataset.id}`,
      });
    },
    cancelOrder(event) {
      wx.navigateTo({
        url: `/packageA/pages/cancel-order/index?id=${event.currentTarget.dataset.id}`,
      });
    },
  },
});
